{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "\n",
    "from bs4 import BeautifulSoup\n",
    "\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_soup(url):\n",
    "    headers={'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'}\n",
    "    response=requests.get(url,headers=headers)\n",
    "    soup=BeautifulSoup(response.text)\n",
    "    return soup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_sex(class_name):\n",
    "    if class_name==['member_boy_ico']:\n",
    "        return '男'\n",
    "    else:\n",
    "        return '女'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_info(info_url):\n",
    "    info_soup=get_soup(info_url)\n",
    "    titles=info_soup.select('div.pho_info>h4')\n",
    "\n",
    "    addresses=info_soup.select('span.pr5')\n",
    "    prices=info_soup.select('#pricePart > div.day_l > span')\n",
    "    imgs=info_soup.select('div.pho_show_big > div > img#curBigImage')\n",
    "    names=info_soup.select('a.lorder_name')\n",
    "    sexs=info_soup.select('div.js_box>div>h6>span')\n",
    "\n",
    "    for title,address,price,img,name,sex in zip(titles,addresses,prices,imgs,names,sexs):\n",
    "        data={'title':title.get_text().strip(),\n",
    "             'address':address.get_text().strip(),\n",
    "             'price':price.get_text().strip(),\n",
    "             'img':img.get(\"src\"),\n",
    "             'sex':get_sex(sex.get(\"class\")),\n",
    "             }\n",
    "    print(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_link(url):\n",
    "    soup =get_soup(url)\n",
    "    links=soup.select('#page_list > ul > li >a')\n",
    "    for link in links:\n",
    "        href=link.get(\"href\")\n",
    "        #print(href)\n",
    "        get_info(href)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "urls=['http://bj.xiaozhu.com/search-duanzufang-p{}-0/'.format(number) for number in range(1,15)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'title': '国贸 欢乐谷 双井地铁7号线附近豪华Foft', 'address': '北京市朝阳区沿海赛洛城', 'price': '498', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,35,2426,1800,1200,d56014de.jpg', 'sex': '男'}\n",
      "{'title': '国贸CBD百子湾地铁-黑骑士-loft可拍摄', 'address': '北京市朝阳区沿海赛洛城', 'price': '428', 'img': 'https://image.xiaozhustatic1.com/00,800,533/12,0,52,18924,1800,1200,19888a1c.jpg', 'sex': '女'}\n",
      "{'title': '二环地铁线整栋Loft  南锣后海故宫天安门', 'address': '北京市东城区地安门内大街', 'price': '435', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,32,2915,1800,1200,fca8d2de.jpg', 'sex': '女'}\n",
      "{'title': '步行301医院1分钟/30步到五棵松地铁站', 'address': '北京市海淀区复兴路30号', 'price': '399', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,91,23512,1800,1200,67742b38.jpg', 'sex': '女'}\n",
      "{'title': '特价国贸华贸7号线地铁宜家样板间家庭影院整租', 'address': '北京市朝阳区百子园16号后现代城', 'price': '398', 'img': 'https://image.xiaozhustatic1.com/00,800,533/7,0,26,14201,1800,1200,1bf4b521.jpg', 'sex': '女'}\n",
      "{'title': '良乡大学城 地铁直达 黑糖民宿（观想）', 'address': '北京市房山区睿府书香10号院10号楼', 'price': '228', 'img': 'https://image.xiaozhustatic1.com/00,800,533/51,0,43,9879,1800,1200,aae0c537.jpg', 'sex': '男'}\n",
      "{'title': '影咖房。近北京南站 公益西桥 独立公寓', 'address': '北京市丰台区东亚三环', 'price': '388', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,89,1627,1800,1200,92ac9ecb.jpg', 'sex': '女'}\n",
      "{'title': '北关地铁站旁，直通南锣鼓巷，五星级智能公寓', 'address': '北京市通州区永顺南街新光大中心', 'price': '298', 'img': 'https://image.xiaozhustatic1.com/00,800,533/11,0,38,13885,1800,1200,caf11181.jpg', 'sex': '女'}\n",
      "{'title': '通州运河核心区，北关地铁站旁，五星级智能公寓', 'address': '北京市通州区永顺南街新光大中心', 'price': '298', 'img': 'https://image.xiaozhustatic1.com/00,800,533/10,0,74,22583,1800,1200,efd48d06.jpg', 'sex': '女'}\n",
      "{'title': '直达故宫天安门/西站南站/7号、14号双地铁', 'address': '北京市朝阳区西大望路63号东方雅苑', 'price': '358', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,51,14481,1800,1200,e3d52568.jpg', 'sex': '女'}\n",
      "{'title': '百子湾国贸CBD北欧简约公寓', 'address': '北京市朝阳区后现代城6号楼', 'price': '358', 'img': 'https://image.xiaozhustatic1.com/00,800,533/3,0,8,1147,1800,1200,cee49ff9.jpg', 'sex': '男'}\n",
      "{'title': '【喵2】双井富力广场/国贸世贸天阶小屋', 'address': '北京市朝阳区双井北里小区', 'price': '398', 'img': 'https://image.xiaozhustatic1.com/00,800,533/51,0,47,6556,1800,1200,35f6e85e.jpg', 'sex': '女'}\n",
      "{'title': '初见黎戈.温馨整租地铁景泰站天坛南门直达南站', 'address': '北京市丰台区景泰西里西区', 'price': '498', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,49,24365,1800,1200,2554932d.jpg', 'sex': '女'}\n",
      "{'title': '国贸三里屯欢乐谷7号线-异域民族Loft小窝', 'address': '北京市朝阳区百子湾地铁站沿海赛洛城', 'price': '498', 'img': 'https://image.xiaozhustatic1.com/00,800,533/10,0,30,4357,1800,1201,f4da6792.jpg', 'sex': '女'}\n",
      "{'title': '石景山万达广场：风情大床房', 'address': '北京市石景山区石景山路甲十八号院', 'price': '330', 'img': 'https://image.xiaozhustatic1.com/00,800,533/13,0,43,10901,1800,1200,71742631.jpg', 'sex': '男'}\n",
      "{'title': '国贸CBD核心双井地铁附近-禅意主题开间', 'address': '北京市朝阳区东柏街10号', 'price': '418', 'img': 'https://image.xiaozhustatic1.com/00,800,533/51,0,68,9119,1800,1200,84ac4618.jpg', 'sex': '女'}\n",
      "{'title': '【享住】百子湾国贸近双井蓝色地中海欧陆文艺屋', 'address': '北京市朝阳区百子湾路金都杭城', 'price': '388', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,78,8855,1800,1200,14272c42.jpg', 'sex': '女'}\n",
      "{'title': '【北京1家】8人loft紧邻天安门天坛地铁', 'address': '北京市东城区珠市口东大街', 'price': '508', 'img': 'https://image.xiaozhustatic1.com/00,800,533/11,0,24,7843,1800,1200,7457c5f4.jpg', 'sex': '女'}\n",
      "{'title': '【都市家】#冬季大促#万寿路地铁阳光温馨两居', 'address': '北京市海淀区复兴路甲49号院', 'price': '518', 'img': 'https://image.xiaozhustatic1.com/00,800,533/16,0,83,4588,1800,1200,783e20b8.jpg', 'sex': '女'}\n",
      "{'title': '地铁直达南锣鼓巷*朝北大悦城*青年汇精致小窝', 'address': '北京市朝阳区甘露园中里青年汇佳园', 'price': '347', 'img': 'https://image.xiaozhustatic1.com/00,800,533/12,0,33,18646,1800,1200,97442f21.jpg', 'sex': '男'}\n",
      "{'title': '北关地铁站 豪华装修 全新五星级高级公寓', 'address': '北京市通州区永顺南街新光大中心', 'price': '338', 'img': 'https://image.xiaozhustatic1.com/00,800,533/10,0,57,22146,1800,1200,cddcfe53.jpg', 'sex': '女'}\n",
      "{'title': '三环/紧临地铁/北京南站/南苑机场/简约一居', 'address': '北京市丰台区马家堡西路东亚三环小区', 'price': '298', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,7,5381,1800,1200,4c7ca895.jpg', 'sex': '女'}\n",
      "{'title': '日式优选地铁望京SOHO798国展高端商旅', 'address': '北京市朝阳区望京园609号楼悠乐汇A区', 'price': '328', 'img': 'https://image.xiaozhustatic1.com/00,800,533/12,0,37,25374,1800,1200,e7945447.jpg', 'sex': '女'}\n",
      "{'title': '北京西站/军事博物馆双地铁/北京世纪坛医院', 'address': '北京市海淀区北蜂窝103号', 'price': '498', 'img': 'https://image.xiaozhustatic1.com/00,800,533/51,0,21,6944,1800,1200,ac90bf21.jpg', 'sex': '男'}\n",
      "{'title': '国贸双井大望路10号线地铁阳光充沛的大床房', 'address': '北京市朝阳区双井桥北东柏街10号院', 'price': '368', 'img': 'https://image.xiaozhustatic1.com/00,800,533/16,0,70,104,1800,1200,1c6bb688.jpg', 'sex': '男'}\n",
      "{'title': '国贸CBD地铁十号线双井观景大开间', 'address': '北京市朝阳区百子湾路32号院苹果社区北区', 'price': '368', 'img': 'https://image.xiaozhustatic1.com/00,800,533/9,0,23,11273,1800,1200,cddcb934.jpg', 'sex': '女'}\n",
      "{'title': '通州运河核心区，北关地铁站旁，五星级智能公寓', 'address': '北京市通州区永顺南街新光大中心8BC', 'price': '298', 'img': 'https://image.xiaozhustatic1.com/00,800,533/10,0,56,22409,1800,1200,7d0495de.jpg', 'sex': '女'}\n",
      "{'title': '家原5号 近五棵松 可洗衣 可做饭 可加床', 'address': '北京市海淀区四季青椿楸嘉园', 'price': '388', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,60,13052,1440,1080,09051006.jpg', 'sex': '女'}\n",
      "{'title': '达官营 临近西站南站儿童医院音乐学院独立一居', 'address': '北京市西城区广安门外大街1达官营地铁', 'price': '398', 'img': 'https://image.xiaozhustatic1.com/00,800,533/11,0,57,5817,1800,1200,b12587c6.jpg', 'sex': '女'}\n",
      "{'title': '阜成门阜外医院儿童医院温馨舒适便利大床两居', 'address': '北京市西城区南礼士路甲一号院', 'price': '530', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,84,28703,3000,2000,ec02bee2.jpg', 'sex': '男'}\n",
      "{'title': '301医院/五棵松地铁/玉泉路地铁/天安门', 'address': '北京市海淀区嘉德公寓', 'price': '388', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,75,10323,1800,1200,43e17bcd.jpg', 'sex': '男'}\n",
      "{'title': '步行5分钟到301医院/五棵松地铁天安门西站', 'address': '北京市海淀区西翠路', 'price': '498', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,1,5637,1800,1200,eda82e43.jpg', 'sex': '男'}\n",
      "{'title': '西直门北欧民宿', 'address': '北京市海淀区文慧园西路56号公寓', 'price': '428', 'img': 'https://image.xiaozhustatic1.com/00,800,533/8,0,37,2637,1800,1200,e5230056.jpg', 'sex': '女'}\n",
      "{'title': '近天安门国贸前门北京站同仁协和豪华公寓', 'address': '北京市东城区冠城名敦道', 'price': '650', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,87,27714,1800,1201,5ae7b6b2.jpg', 'sex': '男'}\n",
      "{'title': '北京西站欢乐谷Loft温馨绿叶小屋', 'address': '北京市朝阳区沿海赛洛城', 'price': '398', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,10,5659,1800,1200,81094bee.jpg', 'sex': '女'}\n",
      "{'title': '16传媒大学 高碑店 四惠干净舒适一居', 'address': '北京市朝阳区超级蜂巢', 'price': '265', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,3,14695,3000,2000,7152e7b4.jpg', 'sex': '男'}\n",
      "{'title': '6号线地铁青年路站大悦城朝阳公园妇产医院', 'address': '北京市朝阳区平房乡姚家园东里8号院5号楼', 'price': '368', 'img': 'https://image.xiaozhustatic1.com/00,800,533/12,0,18,13693,3000,2000,d95d1f09.jpg', 'sex': '女'}\n",
      "{'title': '8知寓Life，西单南站 博爱医院 公益西桥', 'address': '北京市丰台区马家堡西路36号院东亚三环2号楼', 'price': '318', 'img': 'https://image.xiaozhustatic1.com/00,800,533/12,0,22,25121,1800,1200,2e49d3bd.jpg', 'sex': '男'}\n",
      "{'title': '动物园站4/6/9号线直达王府井故宫清华北大', 'address': '北京市海淀区新苑街1号院', 'price': '418', 'img': 'https://image.xiaozhustatic1.com/00,800,533/12,0,45,16124,1800,1200,7207441d.jpg', 'sex': '女'}\n",
      "{'title': '1知寓Life，南站 西单 博爱医院南苑机场', 'address': '北京市丰台区马家堡西路36号院4号楼', 'price': '388', 'img': 'https://image.xiaozhustatic1.com/00,800,533/12,0,15,25142,1800,1200,bb6750ec.jpg', 'sex': '男'}\n",
      "{'title': '角门大红门南站南苑机场地铁10号线地铁1居室', 'address': '北京市丰台区怡然家园6号院3号楼', 'price': '336', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,15,27313,1800,1200,89dd4474.jpg', 'sex': '女'}\n",
      "{'title': '北师大附近北欧粉色风12', 'address': '北京市海淀区文慧园路', 'price': '388', 'img': 'https://image.xiaozhustatic1.com/00,800,533/8,0,0,9218,1800,1200,b1b2a7eb.jpg', 'sex': '女'}\n",
      "{'title': '国贸CBD双井地铁7号线大郊亭易购复古机车风', 'address': '北京市朝阳区百子湾甲16号', 'price': '358', 'img': 'https://image.xiaozhustatic1.com/00,800,533/12,0,72,16741,1800,1200,a490cd37.jpg', 'sex': '男'}\n",
      "{'title': '长租实惠双人玉泉路地铁西客站水魔方国科大', 'address': '北京市丰台区兆丰园3区', 'price': '139', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,62,5746,1800,1200,894a74c9.jpg', 'sex': '女'}\n",
      "{'title': '西直门地铁附近高楼层一居室上线啦', 'address': '北京市海淀区文慧园西路', 'price': '428', 'img': 'https://image.xiaozhustatic1.com/00,800,533/6,0,88,4323,1800,1200,a860bfb3.jpg', 'sex': '女'}\n",
      "{'title': '｛美式少女系｝故宫、天安门、国贸投影大床房', 'address': '北京市朝阳区时代国际嘉园 地铁300米', 'price': '458', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,10,5259,1800,1200,b827c1d1.jpg', 'sex': '男'}\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'title': '【青蕖】朝阳北路十里堡地铁旁一室一厅阳光南向', 'address': '北京市朝阳区十里堡北里13号楼', 'price': '398', 'img': 'https://image.xiaozhustatic1.com/00,800,533/4,0,33,7723,1800,1200,ea158d5e.jpg', 'sex': '女'}\n",
      "{'title': '金台路华贸国贸妇产医院6号线|走心的小家', 'address': '北京市朝阳区甜水园东里', 'price': '313', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,4,11554,2999,2000,83c5bfee.jpg', 'sex': '女'}\n",
      "{'title': '国贸双井地铁10号线，60平米阳光大床房', 'address': '北京市朝阳区百子湾路32号院苹果社区北区2号楼', 'price': '358', 'img': 'https://image.xiaozhustatic1.com/00,800,533/8,0,75,14569,1800,1200,bfe7fd9b.jpg', 'sex': '女'}\n",
      "{'title': '26#知寓Life，南站 南苑机场 公益西桥', 'address': '北京市丰台区马家堡西路36号院东亚三环', 'price': '298', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,70,6898,1800,1200,2fdc0012.jpg', 'sex': '男'}\n",
      "{'title': '【玫瑰屋】纯实木精装新房/14号地铁北京西站', 'address': '北京市丰台区大瓦窑中路16号', 'price': '398', 'img': 'https://image.xiaozhustatic1.com/00,800,533/8,0,85,5987,1800,1200,5dfad6e0.jpg', 'sex': '女'}\n",
      "{'title': '【麻雀小窝】天坛医院 总部基地 西客站 地铁', 'address': '北京市丰台区丰台南路', 'price': '358', 'img': 'https://image.xiaozhustatic1.com/00,800,533/3,0,68,4233,1800,1200,649284a9.jpg', 'sex': '女'}\n",
      "{'title': '紧邻车道沟地铁北京师范大学化工大学南向小两居', 'address': '北京市海淀区北洼西里', 'price': '480', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,47,12881,1800,1200,bd5bb72c.jpg', 'sex': '女'}\n",
      "{'title': '牛街阳光大房整租7号2号线南站西站直达超便利', 'address': '北京市西城区牛街西里二区', 'price': '333', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,46,12140,2668,2000,7e1e585d.jpg', 'sex': '男'}\n",
      "{'title': '安贞医院旁 安华桥地铁口鸟巢附近 两居室整租', 'address': '北京市朝阳区安贞西里四区16号楼', 'price': '498', 'img': 'https://image.xiaozhustatic1.com/00,800,533/12,0,61,17801,1800,1200,4bba8082.jpg', 'sex': '女'}\n",
      "{'title': '义和庄整套短租家庭房地铁直达南站西单动物园', 'address': '北京市大兴区义和庄地铁站万科天地', 'price': '328', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,3,19595,2999,2000,50ad28b6.jpg', 'sex': '女'}\n",
      "{'title': '西直门地铁2号线简约风格', 'address': '北京市海淀区文慧园路56号公寓', 'price': '428', 'img': 'https://image.xiaozhustatic1.com/00,800,533/8,0,72,9254,1800,1200,36d29bfd.jpg', 'sex': '女'}\n",
      "{'title': '【米宿.富力城】CBD国贸天安门楼下地铁站', 'address': '北京市朝阳区富力城A区', 'price': '499', 'img': 'https://image.xiaozhustatic1.com/00,800,533/12,0,94,26974,1800,1200,98b4452d.jpg', 'sex': '女'}\n",
      "{'title': '紧邻五号线奥森鸟巢立水桥天通苑整租一居26', 'address': '北京市昌平区龙德紫金', 'price': '298', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,2,7677,1800,1201,354a14f0.jpg', 'sex': '男'}\n",
      "{'title': '立水桥5/13号线鸟巢水立方温馨典雅一居室', 'address': '北京市朝阳区北苑路旭辉奥都', 'price': '338', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,43,5487,1800,1201,3894bf78.jpg', 'sex': '女'}\n",
      "{'title': '可长租床位单间玉泉路地铁直达天安门水魔方科大', 'address': '北京市丰台区兆丰园3区', 'price': '109', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,20,5681,1800,1200,95910606.jpg', 'sex': '女'}\n",
      "{'title': '离地铁10号线仅30米近国贸天坛天安门', 'address': '北京市丰台区成寿寺路134号', 'price': '368', 'img': 'https://image.xiaozhustatic1.com/00,800,533/9,0,90,8707,1800,1200,d8193969.jpg', 'sex': '男'}\n",
      "{'title': '【特惠】安贞医院，中日友好医院温馨两居室', 'address': '北京市朝阳区和平里青年沟8区', 'price': '413', 'img': 'https://image.xiaozhustatic1.com/00,800,533/12,0,43,24836,1800,1201,3d9ed81d.jpg', 'sex': '女'}\n",
      "{'title': '小家商旅 近首都机场新国展地铁口免费接送', 'address': '北京市顺义区天裕昕园', 'price': '498', 'img': 'https://image.xiaozhustatic1.com/00,800,533/9,0,89,11261,1800,1201,a3144379.jpg', 'sex': '男'}\n",
      "{'title': '国贸欢乐谷7号线英伦countrysid风情', 'address': '北京市朝阳区沿海赛洛城408号楼', 'price': '365', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,90,19491,1800,1200,6adea294.jpg', 'sex': '男'}\n",
      "{'title': '西直门星空之城', 'address': '北京市海淀区文慧园西路56公寓', 'price': '398', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,38,7184,1440,1080,0af9866a.jpg', 'sex': '女'}\n",
      "{'title': '北京南站天安门故宫马家堡4号线满杯西柚房', 'address': '北京市丰台区马家堡西里30号楼', 'price': '428', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,31,19465,2999,2000,993b9f3f.jpg', 'sex': '男'}\n",
      "{'title': '将台地铁798望京soho-高层落地窗观景房', 'address': '北京市朝阳区酒仙桥路与将台西路交叉口，飘home...', 'price': '428', 'img': 'https://image.xiaozhustatic1.com/00,800,533/8,0,58,4766,1800,1200,6fb8d0db.jpg', 'sex': '男'}\n",
      "{'title': '紧邻华贸城福熙大道乐想汇公寓美式一居品茶', 'address': '北京市朝阳区清河营东路二号院乐想汇', 'price': '368', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,15,28119,1800,1200,eb500b46.jpg', 'sex': '女'}\n",
      "{'title': '西二旗（13号线）上地、联想、百度、小米', 'address': '北京市海淀区西二旗大街领袖新硅谷', 'price': '520', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,89,18936,1800,1200,1a6723e5.jpg', 'sex': '女'}\n",
      "{'title': '国贸CBD双井地铁7号线大郊亭欧式优雅一居', 'address': '北京市朝阳区双井街道', 'price': '398', 'img': 'https://image.xiaozhustatic1.com/00,800,533/3,0,44,124,1800,1200,411eb0a0.jpg', 'sex': '男'}\n",
      "{'title': '长租优惠、地铁直达南锣鼓巷、后海北欧复试整租', 'address': '北京市朝阳区五里桥一街北京像素南区2号楼', 'price': '389', 'img': 'https://image.xiaozhustatic1.com/00,853,533/14,0,38,19763,3199,2000,077b0b96.jpg', 'sex': '女'}\n",
      "{'title': '国贸CBD百子湾地铁-秘密花园精装Loft', 'address': '北京市朝阳区沿海赛洛城', 'price': '398', 'img': 'https://image.xiaozhustatic1.com/00,800,533/12,0,95,15951,1800,1200,634c92a1.jpg', 'sex': '女'}\n",
      "{'title': '一号线五棵松 学霸文字四人床铺上铺', 'address': '北京市丰台区青塔芳园', 'price': '79', 'img': 'https://image.xiaozhustatic1.com/00,800,533/14,0,1,24353,2666,2000,1f1627f5.jpg', 'sex': '女'}\n",
      "{'title': '特价六号线十里堡地铁阳关充沛实木大床整套一居', 'address': '北京市朝阳区十里堡北区6号楼', 'price': '388', 'img': 'https://image.xiaozhustatic1.com/00,800,533/7,0,99,10498,1800,1200,e837e871.jpg', 'sex': '女'}\n",
      "{'title': '北苑地铁13号直达东直门西直门美式大床房整租', 'address': '北京市朝阳区来广营 北苑东路水岸南街清河营东路...', 'price': '388', 'img': 'https://image.xiaozhustatic1.com/00,800,533/15,0,11,18904,1800,1201,3f8dcde6.jpg', 'sex': '女'}\n",
      "{'title': '资和信精装公寓可做饭', 'address': '北京市丰台区设计师广场', 'price': '398', 'img': 'https://image.xiaozhustatic1.com/00,800,533/12,0,82,1673,1800,1200,fafaf41d.jpg', 'sex': '女'}\n",
      "{'title': '石景山万达广场：雅悦竹风房', 'address': '北京市石景山区石景山路甲18号院', 'price': '330', 'img': 'https://image.xiaozhustatic1.com/00,800,533/13,0,41,10436,1800,1200,49abaef7.jpg', 'sex': '男'}\n",
      "{'title': '天安门天坛王府井双地铁商品房高档小区大两居', 'address': '北京市东城区新裕家园东区', 'price': '618', 'img': 'https://image.xiaozhustatic1.com/00,800,533/12,0,61,16094,1800,1200,9afff143.jpg', 'sex': '女'}\n",
      "{'title': '小清新两居十里河地铁直达国贸北京南近肿瘤医院', 'address': '北京市朝阳区东三环左安路', 'price': '398', 'img': 'https://image.xiaozhustatic1.com/00,800,533/4,0,64,7943,1800,1200,a51f9a84.jpg', 'sex': '女'}\n",
      "{'title': '【享住】百子湾地铁站双井国贸大望路阳光大床房', 'address': '北京市朝阳区金都心语', 'price': '388', 'img': 'https://image.xiaozhustatic1.com/00,800,533/13,0,25,10422,1800,1200,bd8575b9.jpg', 'sex': '女'}\n",
      "{'title': '北京301武警总院阜成路附近私密豪华1居公寓', 'address': '北京市海淀区塞纳维拉永定华庭', 'price': '416', 'img': 'https://image.xiaozhustatic1.com/00,800,533/4,0,66,6608,1800,1200,7c188c0d.jpg', 'sex': '男'}\n"
     ]
    },
    {
     "ename": "UnboundLocalError",
     "evalue": "local variable 'data' referenced before assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mUnboundLocalError\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-65-a52e1e570c8f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0msingle_url\u001b[0m \u001b[0;32min\u001b[0m \u001b[0murls\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m     \u001b[0mget_link\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msingle_url\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      3\u001b[0m     \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m15\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-55-ff7dba3edf72>\u001b[0m in \u001b[0;36mget_link\u001b[0;34m(url)\u001b[0m\n\u001b[1;32m      5\u001b[0m         \u001b[0mhref\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlink\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"href\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      6\u001b[0m         \u001b[0;31m#print(href)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m         \u001b[0mget_info\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhref\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m<ipython-input-52-71ef0bfcaab6>\u001b[0m in \u001b[0;36mget_info\u001b[0;34m(info_url)\u001b[0m\n\u001b[1;32m     16\u001b[0m              \u001b[0;34m'sex'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mget_sex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msex\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"class\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     17\u001b[0m              }\n\u001b[0;32m---> 18\u001b[0;31m     \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mUnboundLocalError\u001b[0m: local variable 'data' referenced before assignment"
     ]
    }
   ],
   "source": [
    "for single_url in urls:\n",
    "    get_link(single_url)\n",
    "    time.sleep(15)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
